#ifndef STANDARDFUNCTIONS_HPP
#define STANDARDFUNCTIONS_HPP

#include <cmath>
#include "functor.hpp"

namespace TermStructure
{

    //!Error Function
	template<typename T>
	class ErrorFunction:AbstractFunctor<T>
	{
	public:
		virtual T operator()(const T& x) const
		{
			if (x==0)
			{
				return 0;
			}
			else
			{
				return (x>0?1:(-1))*sqrt(1-exp(-x*x*(4.0/M_PI+0.140012*x*x)/(1+0.140012*x*x))); 
			}
		}

	};
    //!Inverse Error Function
	template<typename T>
	class InverseErrorFunction:AbstractFunctor<T>
	{
	public:
		virtual T operator()(const T& x) const
		{
			if (x==0)
			{
				return 0;
			}
			else
			{
				return (x>0?1:(-1))*sqrt(sqrt((2/M_PI/0.140012+log(1-x*x)/2)*(2/M_PI/0.140012+log(1-x*x)/2)-log(1-x*x)/0.140012)-(2/M_PI/0.140012+log(1-x*x)/2));
			}
		}
	};
}


#endif